home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / helper / source / file.c < prev    next >
Text File  |  1991-10-18  |  41KB  |  1,761 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <stdarg.h>
  4. #include    <string.h>
  5. #include    <ctype.h>
  6. #include    <fmc.h>
  7. #include    <mos.h>
  8. #include    "dir.h"
  9. #include    "scrn.h"
  10. #include    "keyword.h"
  11. #include    "graphic.h"
  12. #include    "event.h"
  13. #include    "coldef.h"
  14.  
  15. #define    TRUE    1
  16. #define    FALSE    0
  17. #define    ERR    (-1)
  18.  
  19. #define    LIN_MAX        80
  20. #define    TAB        8
  21. #define    LPT_LINE    59
  22.  
  23. #define    PAGE        0x40000
  24.  
  25. #define    MAX_Y        25
  26. #define    SCRN_Y        52
  27.  
  28. #define    SCRN_X1        0
  29. #define    SCRN_Y1        47
  30. #define    SCRN_X2        639
  31. #define    SCRN_Y2        454
  32.  
  33. #define    BAR_SIZ        (25*8)
  34. #define    BAR_X1        8
  35. #define    BAR_Y1        458
  36. #define    BAR_X2        (BAR_X1+BAR_SIZ+4)
  37. #define    BAR_Y2        (BAR_Y1+19)
  38.  
  39. #define    KAKU_X1        (15*8-4)
  40. #define    KAKU_Y1        180
  41. #define    KAKU_X2        (64*8+3)
  42. #define    KAKU_Y2        280
  43.  
  44. #define    KAKU_MSG_X    ((KAKU_X1+KAKU_X2)/2)
  45. #define    KAKU_MSG_Y    (KAKU_Y1+30)
  46.  
  47. #define    KAKU_CHK_X    ((KAKU_X1+KAKU_X2)/2-(4*8))
  48. #define    KAKU_CHK_Y    (KAKU_Y1+70)
  49.  
  50. #define    KAKU_YES_X    ((KAKU_X1+KAKU_X2)/2-(10*8))
  51. #define    KAKU_YES_Y    (KAKU_Y1+70)
  52.  
  53. #define    KAKU_NO_X    ((KAKU_X1+KAKU_X2)/2+(2*8))
  54. #define    KAKU_NO_Y    (KAKU_Y1+70)
  55.  
  56. #define    BREAK_X1    (13*8-4)
  57. #define    BREAK_Y1    160
  58. #define    BREAK_X2    (66*8+3)
  59. #define    BREAK_Y2    300
  60.  
  61. #define    BREAK_MSG_X    ((BREAK_X1+BREAK_X2)/2)
  62. #define    BREAK_MSG_Y    (BREAK_Y1+30)
  63.  
  64. #define    BREAK_BAR_SIZ    (41*8)
  65. #define    BREAK_BAR_X    (BREAK_X1+6*8)
  66. #define    BREAK_BAR_Y    (BREAK_Y1+70)
  67.  
  68. #define    BREAK_BAR_X1    (BREAK_BAR_X-2)
  69. #define    BREAK_BAR_Y1    (BREAK_BAR_Y-2)
  70. #define    BREAK_BAR_X2    (BREAK_BAR_X+BREAK_BAR_SIZ+2)
  71. #define    BREAK_BAR_Y2    (BREAK_BAR_Y+17)
  72.  
  73. #define    BREAK_CHK_X    ((BREAK_X1+BREAK_X2)/2-(4*8))
  74. #define    BREAK_CHK_Y    (BREAK_Y1+110)
  75.  
  76. typedef struct _LP {
  77.     struct _LP    *next;
  78.     struct _LP    *back;
  79.     char        buf[1];
  80. } LINPTR;
  81.  
  82. void    INKEY_start(void);
  83. void    INKEY_end(void);
  84. int    getch(void);
  85. int    CLIP_box();
  86.  
  87. extern int    cur_x;
  88. extern int    cur_y;
  89.  
  90.        int      cut_mode = FALSE;
  91.        char     cut_buf[2][128];
  92.  
  93. static int    old_line=(-1);
  94. static int    now_line=0;
  95. static int    max_line=0;
  96. static int    now_ofs=0;
  97. static int    slow_ofs=0;
  98. static int    tik_speed=100;
  99. static int    scr_speed=16;
  100. static int    pas_flg=FALSE;
  101. static int    bar_old_x1=(-1);
  102. static int    bar_old_x2=(-1);
  103. static LINPTR    *top_ptr=NULL;
  104. static LINPTR    *now_ptr=NULL;
  105. static BLOCK    *save=NULL;
  106. static char    file_name[128];
  107. static int    break_bar=0;
  108. static BLOCK    *break_save=NULL;
  109. static EVENT    *break_ep=NULL;
  110.  
  111. int    pause(char *form,...)
  112. {
  113.     va_list arg;
  114.     int     n,x1,x2;
  115.     int     cd,sw,bx,by;
  116.     BLOCK   *sp;
  117.     EVENT   *ep=NULL;
  118.     char    tmp[256];
  119.  
  120.     va_start(arg,form);
  121.     vsprintf((char *)tmp,form,arg);
  122.     va_end(arg);
  123.  
  124.     if ( (n = (strlen(tmp) * 8 + 32) / 2) < 160 )
  125.     n = 160;
  126.     x1 = (KAKU_X1 + KAKU_X2) / 2 - n;
  127.     x2 = (KAKU_X1 + KAKU_X2) / 2 + n;
  128.  
  129.     MOS_disp(OFF);
  130.     sp = DSP_push_vram(x1,KAKU_Y1,x2,KAKU_Y2);
  131.     DSP_opbox(x1,KAKU_Y1,x2,KAKU_Y2);
  132.     DSP_wbox(x1,KAKU_Y1,x2,KAKU_Y2,LINE_COL,FILD_COL,M_PSET);
  133.     gputs(KAKU_MSG_X-strlen(tmp)*4,KAKU_MSG_Y,CHR_COL,FILD_COL,tmp);
  134.  
  135.     ep = EVT_sw(ep,0,KAKU_YES_X,KAKU_YES_Y,CHR_COL,WIND_COL," 続  行 ");
  136.     ep = EVT_sw(ep,1,KAKU_NO_X,KAKU_NO_Y,CHR_COL,WIND_COL,  " 中  断 ");
  137.  
  138.     MOS_rdpos(&sw,&bx,&by);
  139.     MOS_setpos((KAKU_X1+KAKU_X2)/2,KAKU_YES_Y+8);
  140.     MOS_disp(ON);
  141.  
  142.     cd = (EVT_wait(ep) == 0 ? TRUE:ERR);
  143.     EVT_free(ep);
  144.  
  145.     MOS_disp(OFF);
  146.     DSP_pop_vram(sp);
  147.     DSP_clbox(x1,KAKU_Y1,x2,KAKU_Y2);
  148.     MOS_setpos(bx,by);
  149.     MOS_disp(ON);
  150.  
  151.     return cd;
  152. }
  153. int    yesno2(char *form,...)
  154. {
  155.     va_list arg;
  156.     int     n,x1,x2;
  157.     int     cd,sw,bx,by;
  158.     BLOCK   *sp;
  159.     EVENT   *ep=NULL;
  160.     char    tmp[256];
  161.  
  162.     va_start(arg,form);
  163.     vsprintf((char *)tmp,form,arg);
  164.     va_end(arg);
  165.  
  166.     if ( (n = (strlen(tmp) * 8 + 32) / 2) < 160 )
  167.     n = 160;
  168.     x1 = (KAKU_X1 + KAKU_X2) / 2 - n;
  169.     x2 = (KAKU_X1 + KAKU_X2) / 2 + n;
  170.  
  171.     MOS_disp(OFF);
  172.     sp = DSP_push_vram(x1,KAKU_Y1,x2,KAKU_Y2);
  173.     DSP_opbox(x1,KAKU_Y1,x2,KAKU_Y2);
  174.     DSP_wbox(x1,KAKU_Y1,x2,KAKU_Y2,LINE_COL,FILD_COL,M_PSET);
  175.     gputs(KAKU_MSG_X-strlen(tmp)*4,KAKU_MSG_Y,CHR_COL,FILD_COL,tmp);
  176.  
  177.     ep = EVT_sw(ep,0,KAKU_YES_X,KAKU_YES_Y,CHR_COL,WIND_COL," は~い ");
  178.     ep = EVT_sw(ep,1,KAKU_NO_X,KAKU_NO_Y,CHR_COL,WIND_COL,  " いいえ ");
  179.  
  180.     MOS_rdpos(&sw,&bx,&by);
  181.     MOS_setpos((KAKU_X1+KAKU_X2)/2,KAKU_YES_Y+8);
  182.     MOS_disp(ON);
  183.  
  184.     cd = (EVT_wait(ep) == 0 ? TRUE:ERR);
  185.     EVT_free(ep);
  186.  
  187.     MOS_disp(OFF);
  188.     DSP_pop_vram(sp);
  189.     DSP_clbox(x1,KAKU_Y1,x2,KAKU_Y2);
  190.     MOS_setpos(bx,by);
  191.     MOS_disp(ON);
  192.  
  193.     return cd;
  194. }
  195. int    yesno(char *form,...)
  196. {
  197.     va_list arg;
  198.     int     n,x1,x2;
  199.     int     cd,sw,bx,by;
  200.     BLOCK   *sp;
  201.     EVENT   *ep=NULL;
  202.     char    tmp[256];
  203.  
  204.     va_start(arg,form);
  205.     vsprintf((char *)tmp,form,arg);
  206.     va_end(arg);
  207.  
  208.     if ( (n = (strlen(tmp) * 8 + 32) / 2) < 160 )
  209.     n = 160;
  210.     x1 = (KAKU_X1 + KAKU_X2) / 2 - n;
  211.     x2 = (KAKU_X1 + KAKU_X2) / 2 + n;
  212.  
  213.     MOS_disp(OFF);
  214.     sp = DSP_push_vram(x1,KAKU_Y1,x2,KAKU_Y2);
  215.     DSP_opbox(x1,KAKU_Y1,x2,KAKU_Y2);
  216.     DSP_wbox(x1,KAKU_Y1,x2,KAKU_Y2,LINE_COL,FILD_COL,M_PSET);
  217.     gputs(KAKU_MSG_X-strlen(tmp)*4,KAKU_MSG_Y,CHR_COL,FILD_COL,tmp);
  218.  
  219.     ep = EVT_sw(ep,0,KAKU_YES_X,KAKU_YES_Y,CHR_COL,WIND_COL," 実  行 ");
  220.     ep = EVT_sw(ep,1,KAKU_NO_X,KAKU_NO_Y,CHR_COL,WIND_COL,  " 取  消 ");
  221.  
  222.     MOS_rdpos(&sw,&bx,&by);
  223.     MOS_setpos((KAKU_X1+KAKU_X2)/2,KAKU_YES_Y+8);
  224.     MOS_disp(ON);
  225.  
  226.     cd = (EVT_wait(ep) == 0 ? TRUE:ERR);
  227.     EVT_free(ep);
  228.  
  229.     MOS_disp(OFF);
  230.     DSP_pop_vram(sp);
  231.     DSP_clbox(x1,KAKU_Y1,x2,KAKU_Y2);
  232.     MOS_setpos(bx,by);
  233.     MOS_disp(ON);
  234.  
  235.     return cd;
  236. }
  237. void    kakunin(char *form,...)
  238. {
  239.     va_list arg;
  240.     int     n,x1,x2;
  241.     int     sw,bx,by;
  242.     BLOCK   *sp;
  243.     EVENT   *ep=NULL;
  244.     char    tmp[256];
  245.  
  246.     va_start(arg,form);
  247.     vsprintf((char *)tmp,form,arg);
  248.     va_end(arg);
  249.  
  250.     if ( (n = (strlen(tmp) * 8 + 32) / 2) < 160 )
  251.     n = 160;
  252.     x1 = (KAKU_X1 + KAKU_X2) / 2 - n;
  253.     x2 = (KAKU_X1 + KAKU_X2) / 2 + n;
  254.  
  255.     MOS_disp(OFF);
  256.     sp = DSP_push_vram(x1,KAKU_Y1,x2,KAKU_Y2);
  257.     DSP_opbox(x1,KAKU_Y1,x2,KAKU_Y2);
  258.     DSP_wbox(x1,KAKU_Y1,x2,KAKU_Y2,ERR_COL,FILD_COL,M_PSET);
  259.     gputs(KAKU_MSG_X-strlen(tmp)*4,KAKU_MSG_Y,ERR_COL,FILD_COL,tmp);
  260.  
  261.     ep = EVT_sw(ep,0,KAKU_CHK_X,KAKU_CHK_Y,ERR_COL,WIND_COL," 確  認 ");
  262.  
  263.     MOS_rdpos(&sw,&bx,&by);
  264.     MOS_setpos((KAKU_X1+KAKU_X2)/2,KAKU_CHK_Y+8);
  265.     MOS_disp(ON);
  266.  
  267.     EVT_wait(ep);
  268.     EVT_free(ep);
  269.  
  270.     MOS_disp(OFF);
  271.     DSP_pop_vram(sp);
  272.     DSP_clbox(x1,KAKU_Y1,x2,KAKU_Y2);
  273.     MOS_setpos(bx,by);
  274.     MOS_disp(ON);
  275. }
  276. void    BREAK_open(char *form,...)
  277. {
  278.     va_list arg;
  279.     char    tmp[256];
  280.  
  281.     va_start(arg,form);
  282.     vsprintf((char *)tmp,form,arg);
  283.     va_end(arg);
  284.  
  285.     MOS_disp(OFF);
  286.     break_save = DSP_push_vram(BREAK_X1,BREAK_Y1,BREAK_X2,BREAK_Y2);
  287.     DSP_opbox(BREAK_X1,BREAK_Y1,BREAK_X2,BREAK_Y2);
  288.     DSP_wbox(BREAK_X1,BREAK_Y1,BREAK_X2,BREAK_Y2,
  289.                     LINE_COL,FILD_COL,M_PSET);
  290.     DSP_rbox(BREAK_BAR_X1,BREAK_BAR_Y1,BREAK_BAR_X2,BREAK_BAR_Y2,
  291.                     LINE_COL,WIND_COL,M_PSET);
  292.     gputs(BREAK_MSG_X-strlen(tmp)*4,BREAK_MSG_Y,
  293.                     CHR_COL,FILD_COL,tmp);
  294.     break_ep = EVT_sw(NULL,0,BREAK_CHK_X,BREAK_CHK_Y,
  295.                     CHR_COL,WIND_COL," 中  断 ");
  296.     DSP_mos(2);
  297.     MOS_disp(ON);
  298.  
  299.     break_bar = (-1);
  300.     EVT_msg_no = ERR;
  301. }
  302. int    BREAK_chk(int max,int pos)
  303. {
  304.     int     n;
  305.  
  306.     if ( (n = (max > 0 ? (BREAK_BAR_SIZ * pos / max):0)) != break_bar ) {
  307.     MOS_disp(OFF);
  308.     DSP_box(BREAK_BAR_X,BREAK_BAR_Y,
  309.         BREAK_BAR_X+n,BREAK_BAR_Y+15,7,M_PSET);
  310.     MOS_disp(ON);
  311.     break_bar = n;
  312.     }
  313.  
  314.     EVT_loop(break_ep);
  315.  
  316.     return (EVT_msg_no == 0 ? TRUE:FALSE);
  317. }
  318. void    BREAK_close(void)
  319. {
  320.     EVT_free(break_ep); break_ep = NULL;
  321.     MOS_disp(OFF);
  322.     DSP_pop_vram(break_save);
  323.     DSP_clbox(BREAK_X1,BREAK_Y1,BREAK_X2,BREAK_Y2);
  324.     DSP_mos(0);
  325.     MOS_disp(ON);
  326. }
  327. static LINPTR  *get_ptr(str)
  328. char    *str;
  329. {
  330.     register LINPTR *lp;
  331.  
  332.     if ( (lp = (LINPTR *)malloc(strlen(str)+sizeof(LINPTR))) != NULL ) {
  333.         lp->next = lp->back = NULL;
  334.     strcpy(lp->buf,str);
  335.     }
  336.     return lp;
  337. }
  338. static LINPTR  *read_line(fp)
  339. FILE    *fp;
  340. {
  341.     int     i,j,ch;
  342.     char    tmp[LIN_MAX + 1];
  343.  
  344.     for ( i = 0 ; i < LIN_MAX ; ) {
  345.         if ( (ch = getc(fp)) == EOF || ch == '\n' )
  346.             break;
  347.     if ( iskanji(ch) ) {
  348.             if ( i == (LIN_MAX - 1) ) {
  349.                 ungetc(ch,fp);
  350.         break;
  351.             }
  352.         tmp[i++] = ch;
  353.             if ( (ch = getc(fp)) == EOF ) {
  354.                 i--;
  355.                 break;
  356.             }
  357.             tmp[i++] = ch;
  358.         } else if ( ch == '\t' ) {
  359.         j = TAB - (i % TAB);
  360.         while ( i < LIN_MAX && j-- > 0 )
  361.         tmp[i++] = ' ';
  362.     } else
  363.         tmp[i++] = ch;
  364.     }
  365.     tmp[i] = '\0';
  366.  
  367.     if ( tmp[0] == '\0' && feof(fp) )
  368.     return NULL;
  369.  
  370.     return get_ptr(tmp);
  371. }
  372. static LINPTR    *read_file(file)
  373. char    *file;
  374. {
  375.     FILE    *fp;
  376.     LINPTR  *lp;
  377.     LINPTR  tp;
  378.     char    *p;
  379.  
  380.     file_name[0] = '\0';
  381.  
  382.     if ( file == NULL || (fp = fopen(file,"r")) == NULL )
  383.     return NULL;
  384.  
  385.     strcpy(file_name,file);
  386.     if ( (p = strrchr(file_name,'\\')) != NULL )
  387.     *p = '\0';
  388.  
  389.     lp = &tp;
  390.     while ( (lp->next = read_line(fp)) != NULL ) {
  391.     lp->next->back = lp;
  392.     lp = lp->next;
  393.     max_line++;
  394.     }
  395.  
  396.     fclose(fp);
  397.     if ( tp.next != NULL )
  398.     tp.next->back = NULL;
  399.     return tp.next;
  400. }
  401. static void    free_file(LINPTR *tp)
  402. {
  403.     LINPTR *lp;
  404.  
  405.     while ( tp != NULL ) {
  406.     lp = tp->next;
  407.     free(tp);
  408.     tp = lp;
  409.     }
  410. }
  411. static void    scrool_bar_disp(void)
  412. {
  413.     int     x1,x2,s;
  414.  
  415.     if ( (s = max_line - now_line) > MAX_Y )
  416.     s = MAX_Y;
  417.  
  418.     if ( bar_old_x1 == (-1) )
  419.     DSP_rbox(BAR_X1,BAR_Y1,BAR_X2,BAR_Y2,LINE_COL,PRG_COL,M_PSET);
  420.     else
  421.     DSP_box(bar_old_x1,BAR_Y1+2,bar_old_x2,BAR_Y2-2,PRG_COL,M_PSET);
  422.  
  423.     if ( max_line > 0 ) {
  424.         x1 = BAR_X1 + 2 + BAR_SIZ * now_line / max_line;
  425.         x2 = BAR_X1 + 2 + BAR_SIZ * (now_line + s) / max_line;
  426.     DSP_box(x1,BAR_Y1+2,x2,BAR_Y2-2,XPRG_COL,M_PSET);
  427.     bar_old_x1 = x1;
  428.     bar_old_x2 = x2;
  429.     }
  430.  
  431.     MENU_mask(BACK_NO,now_line > 0 ? ON:OFF);
  432.     MENU_mask(NEXT_NO,(now_line + MAX_Y) < max_line ? ON:OFF);
  433. }
  434. static void    FILE_disp(int line)
  435. {
  436.     int     i;
  437.     LINPTR  *tp;
  438.  
  439.     while ( line > now_line && now_ptr != NULL && now_ptr->next != NULL ) {
  440.     now_line++;
  441.     now_ptr = now_ptr->next;
  442.     }
  443.     while ( line < now_line && now_ptr != NULL && now_ptr->back != NULL ) {
  444.     now_line--;
  445.     now_ptr = now_ptr->back;
  446.     }
  447.  
  448.     if ( old_line == now_line )
  449.     return;
  450.     old_line = now_line;
  451.  
  452.     MOS_disp(OFF);
  453.     now_ofs += slow_ofs; now_ofs &= 511;
  454.     slow_ofs = 0;
  455.     DSP_offset(1,0,(now_ofs - SCRN_Y)&511);
  456.     tp = now_ptr;
  457.     for ( i = 0 ; i < MAX_Y ; i++ ) {
  458.     if ( tp != NULL ) {
  459.         putstr(tp->buf,PAGE,(i*16+now_ofs)&511);
  460.         tp = tp->next;
  461.     } else
  462.         putstr("",PAGE,(i*16+now_ofs)&511);
  463.     }
  464.     scrool_bar_disp();
  465.     MOS_disp(ON);
  466. }
  467. void    FILE_open(char *file)
  468. {
  469.     MOS_disp(OFF);
  470.     if ( save == NULL )
  471.     save = DSP_push_vram(SCRN_X1,SCRN_Y1,SCRN_X2,479);
  472.     DSP_box(SCRN_X1,SCRN_Y1,SCRN_X2,SCRN_Y2,SCRN_COL,M_PSET);
  473.     gputs(192,220,MENU_COL,SCRN_COL,"テキストファイルを読み込み中です");
  474.     DSP_mos(2);
  475.     MOS_disp(ON);
  476.  
  477.     free_file(top_ptr);
  478.     bar_old_x1 = bar_old_x2 = old_line = (-1);
  479.     max_line = now_line = 0;
  480.     scr_speed = 16;
  481.     slow_ofs = now_ofs = 0;
  482.     top_ptr = now_ptr = read_file(file);
  483.     cut_buf[0][0] = cut_buf[1][0] = '\0';
  484.     FILE_disp(now_line);
  485.  
  486.     MOS_disp(OFF);
  487.     DSP_offset(1,0,(now_ofs - SCRN_Y)&511);
  488.     DSP_box(0,SCRN_Y,639,SCRN_Y+MAX_Y*16-1,0,M_PSET);
  489.     gprintf(49*8,460,XPRG_COL,PRG_COL,"%-30.30s",file_name);
  490.     DSP_mos(0);
  491.     MOS_disp(ON);
  492.     MENU_mask(PRNT_NO,top_ptr == NULL ? OFF:ON);
  493. }
  494. void    FILE_close(void)
  495. {
  496.     free_file(top_ptr);
  497.     top_ptr = now_ptr = NULL;
  498.     MOS_disp(OFF);
  499.     DSP_pop_vram(save);
  500.     DSP_clear(1);
  501.     MOS_disp(ON);
  502.     save = NULL;
  503. }
  504. void    FILE_back(void)
  505. {
  506.     if ( top_ptr == NULL || now_line <= 0 )
  507.     return;
  508.     FILE_disp(now_line - MAX_Y);
  509. }
  510. void    FILE_next(void)
  511. {
  512.     if ( top_ptr == NULL || (now_line + MAX_Y) >= max_line )
  513.     return;
  514.     FILE_disp(now_line + MAX_Y);
  515. }
  516. static void    FILE_one_up(void)
  517. {
  518.     int     i;
  519.     LINPTR  *tp;
  520.  
  521.     if ( (now_line + MAX_Y) > max_line ||
  522.      now_ptr == NULL || now_ptr->next == NULL )
  523.     return;
  524.  
  525.     now_line++;
  526.     old_line++;
  527.     tp = now_ptr = now_ptr->next;
  528.     for ( i = 1 ; tp != NULL && i < MAX_Y ; i++ )
  529.     tp = tp->next;
  530.  
  531.     MOS_disp(OFF);
  532.     putstr((tp == NULL ? "":tp->buf),PAGE,(MAX_Y*16+now_ofs+slow_ofs)&511);
  533.     slow_ofs += 16;
  534.     pas_flg = TRUE;
  535.     scrool_bar_disp();
  536.     MOS_disp(ON);
  537. }
  538. static void    FILE_one_down(void)
  539. {
  540.     if ( now_ptr == NULL || now_ptr->back == NULL )
  541.     return;
  542.  
  543.     now_line--;
  544.     old_line--;
  545.     now_ptr = now_ptr->back;
  546.  
  547.     MOS_disp(OFF);
  548.     putstr(now_ptr->buf,PAGE,(now_ofs+slow_ofs-16)&511);
  549.     slow_ofs -= 16;
  550.     pas_flg = TRUE;
  551.     scrool_bar_disp();
  552.     MOS_disp(ON);
  553. }
  554. static void    OFS_cont(void)
  555. {
  556.     int     n;
  557.  
  558.     if ( slow_ofs > 0 ) {
  559.     n = (slow_ofs > scr_speed ? scr_speed:slow_ofs);
  560.     now_ofs += n; now_ofs &= 511;
  561.     DSP_offset(1,0,(now_ofs - SCRN_Y)&511);
  562.     if ( (slow_ofs -= n) <= 0 && pas_flg != FALSE )
  563.         FILE_one_up();
  564.  
  565.     } else if ( slow_ofs < 0 ) {
  566.     n = (-slow_ofs > scr_speed ? scr_speed:-slow_ofs);
  567.     now_ofs -= n; now_ofs &= 511;
  568.     DSP_offset(1,0,(now_ofs - SCRN_Y)&511);
  569.     if ( (slow_ofs += n) >= 0 && pas_flg != FALSE )
  570.         FILE_one_down();
  571.     }
  572. }
  573. void    FILE_irq(void)
  574. {
  575.     int     i,rc,sw,x,y,sx,sy;
  576.  
  577.     if ( top_ptr == NULL )
  578.     return;
  579.  
  580.     if ( tick_timer >= tik_speed ) {
  581.     tick_timer = 0;
  582.         OFS_cont();
  583.     }
  584.  
  585.     MOS_rdpos(&sw,&x,&y);
  586.     if ( sw == 0 )
  587.     return;
  588.  
  589.     rc = FALSE;
  590.  
  591.     if ( y >= SCRN_Y1 && y <= SCRN_Y2 ) {
  592.     DSP_mos(1);
  593.     do {
  594.         MOS_rdpos(&sw,&sx,&sy);
  595.  
  596.         if ( cut_mode != FALSE && y >= SCRN_Y )
  597.         rc = CLIP_box(sw == 1 ? 0:1,
  598.                   x / 8,(y - SCRN_Y) / 16,(sx - x) / 8);
  599.  
  600.         if ( rc == FALSE ) {
  601.             if ( (i = (sy - y) / 4) < 0 ) {
  602.             i = (y - sy) / 4;
  603.             scr_speed = ((tik_speed = 16 - i) < 0 ? 16:1);
  604.                 if ( slow_ofs <= 0 )
  605.                 FILE_one_up();
  606.             } else if ( i > 0 ) {
  607.             scr_speed = ((tik_speed = 16 - i) < 0 ? 16:1);
  608.                 if ( slow_ofs >= 0 )
  609.                     FILE_one_down();
  610.             } else
  611.             pas_flg = FALSE;
  612.         }
  613.  
  614.         if ( tick_timer >= tik_speed ) {
  615.         tick_timer = 0;
  616.             OFS_cont();
  617.         }
  618.     } while ( sw != 0 );
  619.     DSP_mos(0);
  620.  
  621.     } else if ( x >= BAR_X1 && x <= BAR_X2 &&
  622.      y >= BAR_Y1 && y <= BAR_Y2 ) {
  623.     DSP_mos(1);
  624.     MOS_horizon(BAR_X1,BAR_X2);
  625.     MOS_vertical(BAR_Y1,BAR_Y2-8);
  626.     do {
  627.         FILE_disp((x - BAR_X1) * max_line / BAR_SIZ);
  628.         MOS_rdpos(&sw,&x,&y);
  629.     } while ( sw != 0 );
  630.     MOS_horizon(0,632);
  631.     MOS_vertical(0,470);
  632.     DSP_mos(0);
  633.     }
  634. }
  635. /****************************
  636. static int    LPT_putc(char ch,FILE *fp)
  637. {
  638.     for ( ; ; ) {
  639.     putc(ch,fp);
  640.     if ( !ferror(fp) )
  641.         break;
  642.     if ( pause("プリンタ出力にエラ-が発生しました!") == ERR )
  643.         return ERR;
  644.     clearerr(fp);
  645.     }
  646.     return FALSE;
  647. }
  648. void    FILE_lpt(void)
  649. {
  650.     int     n,ln;
  651.     LINPTR  *lp;
  652.     FILE    *fp;
  653.     char    *p;
  654.  
  655.     if ( top_ptr == NULL )
  656.     return;
  657.  
  658.     if ( yesno("表示している文書をプリンタに出力しますか?") == ERR )
  659.     return;
  660.  
  661.     if ( (fp = fopen("PRN","w")) == NULL ) {
  662.     kakunin("プリンタ出力がオ-プン出来ません");
  663.     return;
  664.     }
  665.  
  666.     BREAK_open("プリンタに出力しています ちょっと待ってね");
  667.  
  668.     n = ln = 0;
  669.     for ( lp = top_ptr ; lp != NULL ; lp = lp->next ) {
  670.     for ( p = lp->buf ; *p != '\0' ; p++ ) {
  671.         if ( LPT_putc(*p,fp) )
  672.         goto ENDOF;
  673.     }
  674.     if ( LPT_putc('\r',fp) || LPT_putc('\n',fp) )
  675.         goto ENDOF;
  676.     if ( ++ln >= LPT_LINE ) {
  677.         if ( LPT_putc('\x0C',fp) )
  678.         goto ENDOF;
  679.         ln = 0;
  680.     }
  681.     if ( BREAK_chk(max_line,++n) )
  682.         break;
  683.     }
  684.     if ( ln > 0 )
  685.     LPT_putc('\x0C',fp);
  686.  
  687. ENDOF:
  688.     fclose(fp);
  689.     BREAK_close();
  690. }
  691. *****************************************/
  692.  
  693. void    FILE_lpt(void)
  694. {
  695.     int     n;
  696.     LINPTR  *lp;
  697.  
  698.     if ( top_ptr == NULL )
  699.     return;
  700.  
  701.     if ( yesno("表示している文書をプリンタに出力しますか?") == ERR )
  702.     return;
  703.  
  704.     if ( LPT_open() == ERR )
  705.     return;
  706.  
  707.     BREAK_open("プリンタに出力しています ちょっと待ってね");
  708.  
  709.     n = 0;
  710.     for ( lp = top_ptr ; lp != NULL ; lp = lp->next ) {
  711.     if ( PRN_puts(lp->buf) )
  712.         goto ENDOF;
  713.     if ( BREAK_chk(max_line,++n) )
  714.         break;
  715.     }
  716.     PRN_close();
  717.  
  718. ENDOF:
  719.     BREAK_close();
  720. }
  721.  
  722. int    iskan(char *p)
  723. {
  724.     if ( iskanji(*p) && iskanji2(*(p+1)) )
  725.     return TRUE;
  726.     else
  727.     return FALSE;
  728. }
  729. int    kan_pos(char *p,int n)
  730. {
  731.     int     i;
  732.  
  733.     for ( i = n ; i > 0 ; ) {
  734.     if ( *p == '\0' ) {
  735.         return (n - i);
  736.  
  737.     } else if ( iskan(p) ) {
  738.         i -= 2;
  739.         p += 2;
  740.  
  741.     } else {
  742.         i--;
  743.         p++;
  744.     }
  745.     }
  746.     return (n + i);
  747. }
  748.  
  749. int    input(int x,int y,int max,char *str)
  750. {
  751.     int     i,n,ch,cd;
  752.     int     ofs=0,len=0,pos=0;
  753.     BLOCK   *sp;
  754.     char    *p;
  755.     char    tmp[128];
  756.  
  757.     INKEY_start();
  758.     pos = len = strlen(str);
  759.  
  760.     memset(tmp,' ',max);
  761.     tmp[max] = '\0';
  762.     gputs(x,y,CHR_COL,WIND_COL,tmp);
  763.  
  764.     for ( ch = 0 ; ; ) {
  765.     ofs = 0;
  766.     n = pos;
  767.     while ( n >= (max - 4) ) {
  768.         ofs += (max / 2);
  769.         ofs = kan_pos(str,ofs);
  770.         n = pos - ofs;
  771.     }
  772.  
  773.     if ( (i = len - ofs) >= max )
  774.         i = kan_pos(str,ofs+max) - ofs;
  775.  
  776.     strncpy(tmp,&(str[ofs]),i);
  777.     tmp[i] = '\0';
  778.  
  779.         sp = DSP_push_vram(x,y,x+(i+3)*8,y+15);
  780.         gputs(x,y,CHR_COL,WIND_COL,tmp);
  781.     DSP_box(x+n*8,y+14,x+n*8+7,y+15,13,M_XOR);
  782.  
  783.     cur_x = x + n * 8;
  784.     cur_y = y;
  785.  
  786.     while ( (ch = getch()) == EOF );
  787.  
  788.     do {
  789.  
  790.         if ( ch == 0x08 && pos > 0 ) {
  791.         pos = kan_pos(str,pos-1);
  792.         p = &(str[pos]);
  793.         n = (iskan(p) ? 2:1);
  794.         strcpy(p,p+n);
  795.         len -= n;
  796.  
  797.         } else if ( ch == 0x7F ) {
  798.         if ( pos < len ) {
  799.             p = &(str[pos]);
  800.             n = (iskan(p) ? 2:1);
  801.             strcpy(p,p+n);
  802.             len -= n;
  803.         }
  804.  
  805.         } else if ( ch == 0x1C ) {
  806.         if ( pos < len )
  807.             pos += (iskan(&(str[pos])) ? 2:1);
  808.  
  809.         } else if ( ch == 0x1D ) {
  810.         if ( pos > 0 )
  811.             pos = kan_pos(str,pos-1);
  812.  
  813.         } else if ( ch >= ' ' && len < 80 ) {
  814.         if ( pos < len ) {
  815.             p = &(str[len]);
  816.             for ( i = len - pos ; i > 0 ; i--,p-- )
  817.             *p = *(p-1);
  818.         }
  819.         str[pos++] = ch;
  820.         len++;
  821.  
  822.         } else if ( ch == 0x0D ) {
  823.         cd = FALSE;
  824.         goto ENDOF;
  825.         } else if ( ch == 0x1B ) {
  826.         cd = ERR;
  827.         goto ENDOF;
  828.         }
  829.  
  830.     } while ( (ch = getch()) != EOF );
  831.  
  832.         DSP_pop_vram(sp);
  833.     }
  834.  
  835. ENDOF:
  836.     DSP_pop_vram(sp);
  837.     str[len] = '\0';
  838.     INKEY_end();
  839.     if ( (i = len) >= max )
  840.      i = kan_pos(str,max);
  841.     strncpy(tmp,&(str[ofs]),i);
  842.     tmp[i] = '\0';
  843.     gputs(x,y,CHR_COL,WIND_COL,tmp);
  844.  
  845.     return cd;
  846. }
  847. int    CLIP_box(box,cx,cy,len)
  848. int    box,cx,cy,len;
  849. {
  850.     int     i,n;
  851.     int     cut_x1,cut_y1,cut_x2,cut_y2;
  852.     LINPTR  *tp;
  853.  
  854.     tp = now_ptr;
  855.     for ( i = 0 ; tp != NULL && i < cy ; i++ )
  856.         tp = tp->next;
  857.  
  858.     if ( tp == NULL )
  859.     return FALSE;
  860.  
  861.     for ( i = 0 ; tp->buf[i] != '\0' && i < cx ; i++ ) {
  862.     if ( iskan(&(tp->buf[i])) ) {
  863.         if ( (i + 1) >= cx )
  864.         break;
  865.         i++;
  866.     }
  867.     }
  868.     cx = i;
  869.  
  870.     for ( n = 0 ; tp->buf[i] != '\0' && n < len ; ) {
  871.     if ( iskan(&(tp->buf[i])) ) {
  872.         cut_buf[box][n++] = tp->buf[i++];
  873.         cut_buf[box][n++] = tp->buf[i++];
  874.     } else {
  875.         cut_buf[box][n++] = tp->buf[i++];
  876.     }
  877.     }
  878.     cut_buf[box][n] = '\0';
  879.  
  880.     if ( (len = n) == 0 )
  881.     return FALSE;
  882.  
  883.     MOS_disp(OFF);
  884.     DSP_page(1);
  885.     cut_x1 = cx * 8;
  886.     cut_y1 = (cy * 16 + now_ofs + slow_ofs) & 511;
  887.     cut_x2 = (cx + len) * 8 - 1;
  888.     cut_y2 = (cy * 16 + 15 + now_ofs + slow_ofs) & 511;
  889.     DSP_vsync();
  890.     DSP_box(cut_x1,cut_y1,cut_x2,cut_y2,8,M_XOR);
  891.     DSP_vsync();
  892.     DSP_box(cut_x1,cut_y1,cut_x2,cut_y2,8,M_XOR);
  893.     DSP_page(0);
  894.     MOS_disp(ON);
  895.  
  896.     return TRUE;
  897. }
  898. /********************************************************************
  899.  
  900.     COPY Funcsion
  901.  
  902. *********************************************************************/
  903.  
  904. static int    dir_make(char *file)
  905. {
  906.     char    *p;
  907.  
  908.     if ( (p = strchr(file,'\\')) != NULL ) {
  909.     *p = '\0';
  910.     if ( chdir(file) ) {
  911.         if ( mkdir(file) ) {
  912.         kakunin("ディレクトリの作成に失敗しました");
  913.         return ERR;
  914.         } else if ( chdir(file) ) {
  915.         kakunin("ディレクトリの移動に失敗しました");
  916.         return ERR;
  917.         }
  918.     }
  919.     *p = '\\';
  920.     dir_make(p+1);
  921.     chdir("..");
  922.     }
  923.     return FALSE;
  924. }
  925. static int    copy(char *src,char *dis)
  926. {
  927.     int     cd,i,n;
  928.     long    fs;
  929.     FILE    *ifp,*ofp;
  930.     char    tmp[4096];
  931.  
  932.     if ( (ifp = fopen(dis,"rb")) != NULL ) {
  933.     fclose(ifp);
  934.     if ( yesno("%sが存在しますコピ-を行いますか?",dis) == ERR )
  935.         return TRUE;
  936.     }
  937.  
  938.     if ( dir_make(dis) == ERR )
  939.     return ERR;
  940.  
  941.     if ( (ifp = fopen(src,"rb")) == NULL ) {
  942.     kakunin("%sファイルがオ-プンできません",src);
  943.     return ERR;
  944.     }
  945.  
  946.     if ( (ofp = fopen(dis,"wb")) == NULL ) {
  947.     fclose(ifp);
  948.     kakunin("%sファイルがオ-プンできません",dis);
  949.     return ERR;
  950.     }
  951.  
  952.     cd = FALSE;
  953.     n = 0;
  954.     fseek(ifp,0L,SEEK_END);
  955.     fs = ftell(ifp);
  956.     rewind(ifp);
  957.  
  958.     BREAK_open("只今%sをコピ-しています",dis);
  959.     while ( (i = fread(tmp,1,4096,ifp)) > 0 ) {
  960.     fwrite(tmp,1,i,ofp);
  961.     n += i;
  962.     if ( ferror(ifp) || ferror(ofp) ) {
  963.         kakunin("ファイルコピ-にエラ-が発生しました");
  964.         cd = ERR;
  965.         break;
  966.     }
  967.     if ( BREAK_chk(fs,n) ) {
  968.         cd = ERR;
  969.         break;
  970.     }
  971.     }
  972.     fclose(ifp);
  973.     fclose(ofp);
  974.     if ( cd == ERR )
  975.     remove(dis);
  976.     BREAK_close();
  977.  
  978.     return cd;
  979. }
  980. static    int    cmds_copy(char *home,char *src,char *dis)
  981. {
  982.     int     n;
  983.     int     cd;
  984.     int     wd=FALSE;
  985.     DIR     *dirp;
  986.     DIRECT  *dp;
  987.     char    *p;
  988.     char    tmp[128];
  989.     char    dmy[128];
  990.  
  991.     if ( src == NULL || *src == '\0' )
  992.     src = "*.*";
  993.  
  994.     if ( src[1] != ':' && home != NULL ) {
  995.     strcpy(tmp,home);
  996.     joint_path(tmp,src);
  997.     } else
  998.     strcpy(tmp,src);
  999.  
  1000.     for ( p = tmp ; *p != '\0' ; p++ );
  1001.  
  1002.     if ( strchr(tmp,'*') != NULL || strchr(tmp,'?') )
  1003.     wd = TRUE;
  1004.     else if ( (p != tmp && *(p-1) == '\\') || isdir(tmp) ) {
  1005.     joint_path(tmp,"*.*");
  1006.     wd = TRUE;
  1007.     }
  1008.  
  1009.     DSP_mos(2);
  1010.     dirp = opendir(tmp);
  1011.     DSP_mos(0);
  1012.  
  1013.     if ( dirp == NULL ) {
  1014.     kakunin("%sファイルが見当たりません",tmp);
  1015.     return ERR;
  1016.     }
  1017.  
  1018.     if ( (src = strrchr(tmp,'\\')) != NULL ||
  1019.      (src = strrchr(tmp,':')) != NULL )
  1020.     src++;
  1021.     else
  1022.     src = tmp;
  1023.  
  1024.     if ( dis == NULL )
  1025.     dis = "";
  1026.  
  1027.     strcpy(dmy,dis);
  1028.  
  1029.     for ( n = 0 ; dmy[n] != '\0' ; n++ );
  1030.     if ( n == 0 || dmy[n-1] == '\\' || dmy[n-1] == ':' )
  1031.      wd = TRUE;
  1032.  
  1033.     if ( wd != FALSE ) {
  1034.     for ( n = 0 ; dmy[n] != '\0' ; n++ );
  1035.     if ( n > 0 && dmy[n-1] != '\\' && dmy[n-1] != ':' )
  1036.         strcat(dmy,"\\");
  1037.     dis = dmy;
  1038.     while ( *dis != '\0' ) dis++;
  1039.     }
  1040.  
  1041.     while ( (dp = readdir(dirp)) != NULL ) {
  1042.     if ( !IS_DIR(dp) ) {
  1043.  
  1044.         strcpy(src,dp->d_name);
  1045.  
  1046.         if ( wd != FALSE )
  1047.         strcpy(dis,dp->d_name);
  1048.  
  1049.         while ( (cd = copy(tmp,dmy)) == ERR ) {
  1050.         if ( pause("コピ-を続行しますか?") == ERR )
  1051.             goto ENDOF;
  1052.         }
  1053.     }
  1054.     }
  1055.  
  1056. ENDOF:
  1057.     closedir(dirp);
  1058.     return (cd == ERR ? ERR:FALSE);
  1059. }
  1060. static    int    cmds_rename(char *src,char *dis)
  1061. {
  1062.     if ( src[0] != '\0' && src[1] == ':' ) {
  1063.     kakunin("絶対パスでのファイル名変更はできません");
  1064.     return ERR;
  1065.     }
  1066.  
  1067.     if ( rename(src,dis) ) {
  1068.     kakunin("ファイル名の変更ができませんでした");
  1069.     return ERR;
  1070.     }
  1071.     return FALSE;
  1072. }
  1073. static    int    cmds_mkdir(char *dir)
  1074. {
  1075.     if ( dir[0] != '\0' && dir[1] == ':' ) {
  1076.     kakunin("絶対パスでのディレクトリ作成はできません");
  1077.     return ERR;
  1078.     }
  1079.  
  1080.     if ( mkdir(dir) ) {
  1081.     kakunin("ディレクトリの作成ができませんでした");
  1082.     return ERR;
  1083.     }
  1084.     return FALSE;
  1085. }
  1086. static    int    cmds_chdir(char *dir)
  1087. {
  1088.     if ( dir[0] != '\0' && dir[1] == ':' ) {
  1089.     kakunin("絶対パスでのディレクトリ移動はできません");
  1090.     return ERR;
  1091.     }
  1092.  
  1093.     if ( chdir(dir) ) {
  1094.     kakunin("ディレクトリの移動ができませんでした");
  1095.     return ERR;
  1096.     }
  1097.     return FALSE;
  1098. }
  1099. static    int    cmdstr(char *src,char *ptn)
  1100. {
  1101.     while ( *ptn != '\0' ) {
  1102.     if ( toupper(*src) != *ptn )
  1103.         return FALSE;
  1104.     src++;
  1105.     ptn++;
  1106.     }
  1107.     if ( *src == '\0' || isspace(*src) )
  1108.     return TRUE;
  1109.     else
  1110.     return FALSE;
  1111. }
  1112.  
  1113. #define    ST_EOF        0
  1114. #define    ST_ELSE        1
  1115. #define    ST_ENDIF    2
  1116.  
  1117. static    char    cmds_dmy[BUFSIZ];
  1118. static    char    cmds_home[BUFSIZ];
  1119.  
  1120. static    int    cmds_line(LINPTR **fp,int rc)
  1121. {
  1122.     int     n;
  1123.     char    *p;
  1124.     char    *s;
  1125.     char    *r;
  1126.  
  1127.     while ( (*fp)->next != NULL ) {
  1128.     (*fp) = (*fp)->next;
  1129.     p = (*fp)->buf;
  1130.  
  1131.     while ( isspace(*p) ) p++;
  1132.  
  1133.     if ( *p == '\0' || *p == '#' )
  1134.         continue;
  1135.  
  1136.     if ( cmdstr(p,"IF") ) {
  1137.         if ( rc == FALSE ) {
  1138.         while ( (n = cmds_line(fp,FALSE)) == ST_ELSE );
  1139.         if ( n == ST_EOF )
  1140.             break;
  1141.  
  1142.         continue;
  1143.         }
  1144.  
  1145.         while ( !isspace(*p) && *p != '\0' ) p++;
  1146.         while ( isspace(*p) ) p++;
  1147.         if ( yesno2(p) == ERR ) {    /* else */
  1148.         if ( (n = cmds_line(fp,FALSE)) == ST_ELSE )
  1149.            n = cmds_line(fp,TRUE);
  1150.  
  1151.         } else {            /* then */
  1152.         if ( (n = cmds_line(fp,TRUE)) == ST_ELSE )
  1153.            n = cmds_line(fp,FALSE);
  1154.         }
  1155.         if ( n == ST_EOF )
  1156.         break;
  1157.  
  1158.         continue;
  1159.  
  1160.     } else if ( cmdstr(p,"ELSE") ) {
  1161.         return ST_ELSE;
  1162.  
  1163.     } else if ( cmdstr(p,"ENDIF") ) {
  1164.         return ST_ENDIF;
  1165.     }
  1166.  
  1167.     if ( rc == FALSE )
  1168.         continue;
  1169.  
  1170.     if ( cmdstr(p,"COPY") ) {
  1171.         while ( !isspace(*p) && *p != '\0' ) p++;
  1172.         while ( isspace(*p) ) p++;
  1173.         s = p;
  1174.         while ( !isspace(*p) && *p != '\0' ) p++;
  1175.         if ( *p != '\0' ) *(p++) = '\0';
  1176.         while ( isspace(*p) ) p++;
  1177.         r = p;
  1178.         while ( !isspace(*r) && *r != '\0' ) r++;
  1179.         *r = '\0';
  1180.         if ( cmds_copy(cmds_home,s,p) )
  1181.         break;
  1182.  
  1183.     } else if ( cmdstr(p,"RENAME") ) {
  1184.         while ( !isspace(*p) && *p != '\0' ) p++;
  1185.         while ( isspace(*p) ) p++;
  1186.         s = p;
  1187.         while ( !isspace(*p) && *p != '\0' ) p++;
  1188.         if ( *p != '\0' ) *(p++) = '\0';
  1189.         while ( isspace(*p) ) p++;
  1190.         r = p;
  1191.         while ( !isspace(*r) && *r != '\0' ) r++;
  1192.         *r = '\0';
  1193.         if ( cmds_rename(s,p) )
  1194.         break;
  1195.  
  1196.     } else if ( cmdstr(p,"MKDIR") ) {
  1197.         while ( !isspace(*p) && *p != '\0' ) p++;
  1198.         while ( isspace(*p) ) p++;
  1199.         r = p;
  1200.         while ( !isspace(*r) && *r != '\0' ) r++;
  1201.         *r = '\0';
  1202.         if ( cmds_mkdir(p) )
  1203.         break;
  1204.  
  1205.     } else if ( cmdstr(p,"CHDIR") ) {
  1206.         while ( !isspace(*p) && *p != '\0' ) p++;
  1207.         while ( isspace(*p) ) p++;
  1208.         r = p;
  1209.         while ( !isspace(*r) && *r != '\0' ) r++;
  1210.         *r = '\0';
  1211.         if ( cmds_chdir(p) )
  1212.         break;
  1213.  
  1214.     } else if ( cmdstr(p,"PAUSE") ) {
  1215.         while ( !isspace(*p) && *p != '\0' ) p++;
  1216.         while ( isspace(*p) ) p++;
  1217.         if ( pause(p) == ERR )
  1218.         break;
  1219.  
  1220.     } else if ( cmdstr(p,"INST") ) {
  1221.         while ( !isspace(*p) && *p != '\0' ) p++;
  1222.         while ( isspace(*p) ) p++;
  1223.         r = p;
  1224.         while ( !isspace(*r) && *r != '\0' ) r++;
  1225.         *r = '\0';
  1226.         strcpy(cmds_dmy,cmds_home);
  1227.         joint_path(cmds_dmy,p);
  1228.         if ( cmds_file(cmds_dmy) )
  1229.         break;
  1230.  
  1231.     } else if ( cmdstr(p,"EXIT") ) {
  1232.         break;
  1233.  
  1234.     }
  1235.     }
  1236.  
  1237.     return ST_EOF;
  1238. }
  1239. static    int    cmds_file(char *file)
  1240. {
  1241.     int     n;
  1242.     LINPTR  tp;
  1243.     LINPTR  *fp;
  1244.     char    *p;
  1245.     char    home[BUFSIZ];
  1246.  
  1247.     n = max_line;
  1248.     if ( (tp.next = read_file(file)) == NULL ) {
  1249.     kakunin("'%s'コマンドが見当たりません",file);
  1250.     return ERR;
  1251.     }
  1252.     max_line = n;
  1253.  
  1254.     strcpy(home,cmds_home);
  1255.     strcpy(cmds_home,file);
  1256.     if ( (p = strrchr(cmds_home,'\\')) != NULL )
  1257.     *p = '\0';
  1258.  
  1259.     fp = &tp;
  1260.     cmds_line(&fp,TRUE);
  1261.  
  1262.     strcpy(cmds_home,home);
  1263.     free_file(tp.next);
  1264.     return FALSE;
  1265. }
  1266. static int    wcopy(char *wild)
  1267. {
  1268.     int     cd;
  1269.     DIR     *dirp;
  1270.     DIRECT  *dp;
  1271.     char    *p;
  1272.     char    *src,*dis;
  1273.     char    tmp[128];
  1274.  
  1275.     if ( (p = strrchr(wild,'\\')) == NULL )
  1276.     p = wild;
  1277.  
  1278.     if ( (p = strrchr(p,'.')) != NULL && strcmp(p,".QQQ") == 0 )
  1279.     return cmds_file(wild);
  1280.  
  1281.     DSP_mos(2);
  1282.     dirp = opendir(wild);
  1283.     DSP_mos(0);
  1284.  
  1285.     if ( dirp == NULL )
  1286.     return TRUE;
  1287.  
  1288.     strcpy(tmp,wild);
  1289.     if ( (p = strrchr(tmp,'\\')) != NULL )
  1290.     p++;
  1291.     else
  1292.     p = tmp;
  1293.  
  1294.     while ( (dp = readdir(dirp)) != NULL ) {
  1295.     if ( !IS_DIR(dp) ) {
  1296.  
  1297.         strcpy(p,dp->d_name);
  1298.         src = tmp;
  1299.         dis = dp->d_name;
  1300.  
  1301.         while ( (cd = copy(src,dis)) == ERR ) {
  1302.         if ( yesno("コピ-を続行しますか?") == ERR )
  1303.             goto ENDOF;
  1304.         }
  1305.     }
  1306.     }
  1307.  
  1308. ENDOF:
  1309.     closedir(dirp);
  1310.     return cd;
  1311. }
  1312.  
  1313. #define    CHDIR_X1    (11*8-4)
  1314. #define    CHDIR_Y1    150
  1315. #define    CHDIR_X2    (68*8+3)
  1316. #define    CHDIR_Y2    340
  1317.  
  1318. #define    CHDIR_MSG_X    ((CHDIR_X1+CHDIR_X2)/2)
  1319. #define    CHDIR_MSG_Y    (CHDIR_Y1+30)
  1320.  
  1321. #define    CHDIR_TTL_X    (CHDIR_X1+3*8)
  1322.  
  1323. #define    CHDIR_BACK_X    (CHDIR_X1+17*8)
  1324. #define    CHDIR_BACK_Y    (CHDIR_Y1+70)
  1325.  
  1326. #define    CHDIR_BACK_X1    (CHDIR_BACK_X-4)
  1327. #define    CHDIR_BACK_Y1    (CHDIR_BACK_Y-9)
  1328. #define    CHDIR_BACK_X2    (CHDIR_BACK_X+2*8+4)
  1329. #define    CHDIR_BACK_Y2    (CHDIR_BACK_Y1+33)
  1330.  
  1331. #define    CHDIR_DRIV_X    (CHDIR_X1+20*8)
  1332. #define    CHDIR_DRIV_Y    (CHDIR_Y1+61)
  1333.  
  1334. #define    CHDIR_DRIV_X1    (CHDIR_DRIV_X)
  1335. #define    CHDIR_DRIV_Y1    (CHDIR_DRIV_Y)
  1336. #define    CHDIR_DRIV_X2    (CHDIR_DRIV_X+33)
  1337. #define    CHDIR_DRIV_Y2    (CHDIR_DRIV_Y+33)
  1338.  
  1339. #define    CHDIR_NEXT_X    (CHDIR_X1+25*8+2)
  1340. #define    CHDIR_NEXT_Y    (CHDIR_Y1+70)
  1341.  
  1342. #define    CHDIR_NEXT_X1    (CHDIR_NEXT_X-4)
  1343. #define    CHDIR_NEXT_Y1    (CHDIR_NEXT_Y-9)
  1344. #define    CHDIR_NEXT_X2    (CHDIR_NEXT_X+2*8+4)
  1345. #define    CHDIR_NEXT_Y2    (CHDIR_NEXT_Y1+33)
  1346.  
  1347. #define    CHDIR_DIR_X    (CHDIR_X1+17*8)
  1348. #define    CHDIR_DIR_Y    (CHDIR_Y1+110)
  1349.  
  1350. #define    CHDIR_YES_X    ((CHDIR_X1+CHDIR_X2)/2-(10*8))
  1351. #define    CHDIR_YES_Y    (CHDIR_Y1+150)
  1352.  
  1353. #define    CHDIR_NO_X    ((CHDIR_X1+CHDIR_X2)/2+(2*8))
  1354. #define    CHDIR_NO_Y    (CHDIR_Y1+150)
  1355.  
  1356. void    COPY_all(int argc,char *argv[])
  1357. {
  1358.     int     now,fg;
  1359.     int     cd,sw,bx,by;
  1360.     BLOCK   *sp;
  1361.     EVENT   *ep=NULL;
  1362.     char    *p,*s;
  1363.     char    tmp[256];
  1364.  
  1365.     if ( yesno("プログラムのコピ-を行いますか?") == ERR )
  1366.     return;
  1367.  
  1368.     MOS_disp(OFF);
  1369.     sp = DSP_push_vram(CHDIR_X1,CHDIR_Y1,CHDIR_X2,CHDIR_Y2);
  1370.     DSP_opbox(CHDIR_X1,CHDIR_Y1,CHDIR_X2,CHDIR_Y2);
  1371.     DSP_wbox(CHDIR_X1,CHDIR_Y1,CHDIR_X2,CHDIR_Y2,LINE_COL,FILD_COL,M_PSET);
  1372.     strcpy(tmp,"コピ-先のドライブなどを指定してください");
  1373.     gputs(CHDIR_MSG_X-strlen(tmp)*4,CHDIR_MSG_Y,CHR_COL,FILD_COL,tmp);
  1374.     gputs(CHDIR_TTL_X,CHDIR_BACK_Y,CHR_COL,FILD_COL,"ドライブ");
  1375.     gputs(CHDIR_TTL_X,CHDIR_DIR_Y,CHR_COL,FILD_COL,"ディレクトリ");
  1376.  
  1377.     now = getdrv();
  1378.     DSP_wbox(CHDIR_BACK_X1,CHDIR_BACK_Y1,
  1379.          CHDIR_BACK_X2,CHDIR_BACK_Y2,LINE_COL,WIND_COL,M_PSET);
  1380.     gputs(CHDIR_BACK_X,CHDIR_BACK_Y,CHR_COL,WIND_COL,"<");
  1381.     ep = EVT_set(ep,1,CHDIR_BACK_X1,CHDIR_BACK_Y1,
  1382.               CHDIR_BACK_X2,CHDIR_BACK_Y2,EVT_proc);
  1383.  
  1384.     ep = EVT_set(ep,2,CHDIR_DRIV_X1,CHDIR_DRIV_Y1,
  1385.               CHDIR_DRIV_X2,CHDIR_DRIV_Y2,EVT_proc);
  1386.  
  1387.     DSP_wbox(CHDIR_NEXT_X1,CHDIR_NEXT_Y1,
  1388.          CHDIR_NEXT_X2,CHDIR_NEXT_Y2,LINE_COL,WIND_COL,M_PSET);
  1389.     gputs(CHDIR_NEXT_X,CHDIR_NEXT_Y,CHR_COL,WIND_COL,">");
  1390.     ep = EVT_set(ep,3,CHDIR_NEXT_X1,CHDIR_NEXT_Y1,
  1391.               CHDIR_NEXT_X2,CHDIR_NEXT_Y2,EVT_proc);
  1392.  
  1393.     sprintf(tmp,"%-34.34s","?");
  1394.     ep = EVT_sw(ep,4,CHDIR_DIR_X,CHDIR_DIR_Y,CHR_COL,WIND_COL,tmp);
  1395.     ep = EVT_sw(ep,5,CHDIR_YES_X,CHDIR_YES_Y,CHR_COL,WIND_COL," 実  行");
  1396.     ep = EVT_sw(ep,6,CHDIR_NO_X,CHDIR_NO_Y,CHR_COL,WIND_COL," 取  消 ");
  1397.     ICON_disp(CHDIR_DRIV_X,CHDIR_DRIV_Y,now);
  1398.  
  1399.     MOS_rdpos(&sw,&bx,&by);
  1400.     MOS_setpos((CHDIR_X1+CHDIR_X2)/2,(CHDIR_Y1+CHDIR_Y2)/2);
  1401.     MOS_disp(ON);
  1402.  
  1403.     tmp[0] = '\0';
  1404.     for ( cd = FALSE ; cd == FALSE ; ) {
  1405.     switch(EVT_wait(ep)) {
  1406.     case 1:
  1407.         do {
  1408.         if ( --now < 0 ) now = 16;
  1409.         } while ( drv_tbl[now] == IS_NON );
  1410.         MOS_disp(OFF);
  1411.         ICON_disp(CHDIR_DRIV_X,CHDIR_DRIV_Y,now);
  1412.         tmp[0] = '\0';
  1413.         gprintf(CHDIR_DIR_X,CHDIR_DIR_Y,CHR_COL,WIND_COL,"%-34.34s","?");
  1414.         MOS_disp(ON);
  1415.         break;
  1416.  
  1417.     case 2:
  1418.         DSP_mos(2);
  1419.         chdrv(now);
  1420.         if ( getdir(tmp) )
  1421.         tmp[0] = 0;
  1422.         DSP_mos(0);
  1423.         MOS_disp(OFF);
  1424.         gprintf(CHDIR_DIR_X,CHDIR_DIR_Y,CHR_COL,WIND_COL,"%-34.34s",
  1425.                     tmp[0] == '\0' ? "?":tmp);
  1426.         MOS_disp(ON);
  1427.         break;
  1428.  
  1429.     case 3:
  1430.         do {
  1431.         if ( ++now >= 17 ) now = 0;
  1432.         } while ( drv_tbl[now] == IS_NON );
  1433.         MOS_disp(OFF);
  1434.         ICON_disp(CHDIR_DRIV_X,CHDIR_DRIV_Y,now);
  1435.         tmp[0] = '\0';
  1436.         gprintf(CHDIR_DIR_X,CHDIR_DIR_Y,CHR_COL,WIND_COL,"%-34.34s","?");
  1437.         MOS_disp(ON);
  1438.         break;
  1439.  
  1440.     case 4:
  1441.         MOS_disp(OFF);
  1442.         input(CHDIR_DIR_X,CHDIR_DIR_Y,33,tmp);
  1443.         gprintf(CHDIR_DIR_X,CHDIR_DIR_Y,CHR_COL,WIND_COL,"%-34.34s",
  1444.                     tmp[0] == '\0' ? "?":tmp);
  1445.         MOS_disp(ON);
  1446.         break;
  1447.  
  1448.     case 5: cd = TRUE; break;
  1449.     case 6: cd = ERR;  break;
  1450.     }
  1451.     }
  1452.  
  1453.     EVT_free(ep);
  1454.     MOS_disp(OFF);
  1455.     DSP_pop_vram(sp);
  1456.     DSP_clbox(CHDIR_X1,CHDIR_Y1,CHDIR_X2,CHDIR_Y2);
  1457.     MOS_setpos(bx,by);
  1458.     DSP_mos(2);
  1459.     MOS_disp(ON);
  1460.  
  1461.     if ( cd == TRUE ) {
  1462.     if ( chdrv(now) ) {
  1463.         kakunin("ドライブが異常なので処理を中断します");
  1464.         cd = ERR;
  1465.         goto ENDOF;
  1466.     }
  1467.     p = tmp;
  1468.     if ( *p == '\\' ) {
  1469.         chdir("\\");
  1470.         p++;
  1471.     }
  1472.     while ( *p != '\0' ) {
  1473.         if ( (s = strchr(p,'\\')) == NULL ) {
  1474.         for ( s = p ; *s != '\0' ; s++ );
  1475.         fg = TRUE;
  1476.         } else
  1477.         fg = FALSE;
  1478.  
  1479.         *s = '\0';
  1480.  
  1481.         if ( *p == '\0' )
  1482.         break;
  1483.  
  1484.         if ( chdir(p) ) {
  1485.         if ( yesno("%sディレクトリを作成しますか?",p) == ERR ) {
  1486.             cd = ERR;
  1487.             goto ENDOF;
  1488.         }
  1489.         if ( mkdir(p) ) {
  1490.             kakunin("ディレクトリの作成に失敗しました");
  1491.             cd = ERR;
  1492.             goto ENDOF;
  1493.         } else if ( chdir(p) ) {
  1494.             kakunin("ディレクトリの移動に失敗しました");
  1495.             cd = ERR;
  1496.             goto ENDOF;
  1497.         }
  1498.         }
  1499.  
  1500.         if ( fg != FALSE )
  1501.         break;
  1502.         *(s++) = '\\';
  1503.         p = s;
  1504.     }
  1505.  
  1506.     while ( argc-- > 0 && wcopy(*(argv++)) != ERR );
  1507.  
  1508.     }
  1509.  
  1510. ENDOF:
  1511.  
  1512.     DSP_mos(0);
  1513. }
  1514.  
  1515. /*************************************************************
  1516. 01234567890123456789012345678901234567890123456789012345678901234567890123456789                01234567890123456789012345678901234567890123456
  1517.                 +---------------------------------------------+
  1518. 0               |                FILE SELECTER            |×||
  1519. 1               |+---++---++---++---++---++---++---++---++---+|
  1520. 2               || A || B || C || D || E || F || G || H || I ||
  1521. 3               |+---++---++---++---++---++---++---++---++---+|
  1522. 4               |+---++---++---++---++---++---++---++---++---+|
  1523. 5               || J || K || L || M || N || O || P || Q || R ||
  1524. 6               |+---++---++---++---++---++---++---++---++---+|
  1525. 7               |******************************************** |
  1526. 8               |xxxxxxxxxx xxx|xxxxxxxxxx xxx|xxxxxxxxxx xxx |
  1527. 9               |xxxxxxxxxx xxx|xxxxxxxxxx xxx|xxxxxxxxxx xxx |
  1528. 10              |xxxxxxxxxx xxx|xxxxxxxxxx xxx|xxxxxxxxxx xxx |
  1529. 11              |xxxxxxxxxx xxx|xxxxxxxxxx xxx|xxxxxxxxxx xxx |
  1530. 12              |xxxxxxxxxx xxx|xxxxxxxxxx xxx|xxxxxxxxxx xxx |
  1531. 13              |ooooooooooooooooooooooooooooooooooooo|<||>||
  1532. 14              +---------------------------------------------+
  1533. **************************************************************/
  1534.  
  1535. #define    FSEL_X1        (16*8)
  1536. #define    FSEL_Y1        (240-8*20)
  1537. #define    FSEL_X2        (62*8)
  1538. #define    FSEL_Y2        (FSEL_Y1+264)
  1539.  
  1540. #define    FSEL_MSG_X    (FSEL_X1+17*8)
  1541. #define    FSEL_MSG_Y    (FSEL_Y1+4)
  1542.  
  1543. #define    FSEL_EXIT_X    (FSEL_X1+43*8-2)
  1544. #define    FSEL_EXIT_Y    (FSEL_Y1+4)
  1545.  
  1546. #define    FSEL_DRIV_X    (FSEL_X1+1*8)
  1547. #define    FSEL_DRIV_Y    (FSEL_Y1+24)
  1548.  
  1549. #define    FSEL_DIR_X    (FSEL_X1+1*8)
  1550. #define    FSEL_DIR_Y    (FSEL_Y1+103)
  1551.  
  1552. #define    FSEL_FILE_X    (FSEL_X1+1*8)
  1553. #define    FSEL_FILE_Y    (FSEL_Y1+124)
  1554.  
  1555. #define    FSEL_BACK_X    ((FSEL_X1+FSEL_X2)/2-4*8)
  1556. #define    FSEL_BACK_Y    (FSEL_Y1+240)
  1557.  
  1558. #define    FSEL_NEXT_X    ((FSEL_X1+FSEL_X2)/2+2*8)
  1559. #define    FSEL_NEXT_Y    (FSEL_Y1+240)
  1560.  
  1561. #define    FSEL_DPOS_X1(n)    (FSEL_DRIV_X+((n)%9)*40)
  1562. #define    FSEL_DPOS_Y1(n)    (FSEL_DRIV_Y+((n)/9)*40)
  1563. #define    FSEL_DPOS_X2(n)    (FSEL_DRIV_X+((n)%9)*40+33)
  1564. #define    FSEL_DPOS_Y2(n)    (FSEL_DRIV_Y+((n)/9)*40+33)
  1565.  
  1566. #define    FSEL_FPOS_X1(n)    (FSEL_FILE_X+((n)/5)*15*8-4)
  1567. #define    FSEL_FPOS_Y1(n)    (FSEL_FILE_Y+((n)%5)*22)
  1568. #define    FSEL_FPOS_X2(n)    (FSEL_FILE_X+((n)/5)*15*8+15*8-6)
  1569. #define    FSEL_FPOS_Y2(n)    (FSEL_FILE_Y+((n)%5)*22+19)
  1570.  
  1571. char    *formname(name)
  1572. char    *name;
  1573. {
  1574.     int     i;
  1575.     char    *p;
  1576.     static char tmp[16];
  1577.  
  1578.     if ( strcmp(name,"..") == 0 || (p = strchr(name,'.')) == NULL )
  1579.         for ( p = name ; *p != '\0' ; p++ );
  1580.  
  1581.     for ( i = 0 ; name < p && i < 8 ; i++ )
  1582.     tmp[i] = *(name++);
  1583.  
  1584.     for ( ; i < 11 ; i++ )
  1585.     tmp[i] = ' ';
  1586.  
  1587.     if ( *p == '.' ) p++;
  1588.  
  1589.     while ( *p != '\0' )
  1590.     tmp[i++] = *(p++);
  1591.  
  1592.     for ( ; i < 14 ; i++ )
  1593.     tmp[i] = ' ';
  1594.  
  1595.     tmp[i] = '\0';
  1596.     return tmp;
  1597. }
  1598. char    *FILE_select(void)
  1599. {
  1600.     int     i,n,cd;
  1601.     int     sw,bx,by;
  1602.     int     drv_old,drv_now;
  1603.     int     pos_old,pos_now;
  1604.     int     dir_flg,dir_max;
  1605.     BLOCK   *sp;
  1606.     EVENT   *ep=NULL;
  1607.     DIR     *dirp;
  1608.     DIRECT  *dp;
  1609.     DIRECT  *file_ptr[15];
  1610.     char    drv_no[17];
  1611.     static char tmp[128];
  1612.  
  1613.     MOS_disp(OFF);
  1614.     sp = DSP_push_vram(FSEL_X1,FSEL_Y1,FSEL_X2,FSEL_Y2);
  1615.     DSP_opbox(FSEL_X1,FSEL_Y1,FSEL_X2,FSEL_Y2);
  1616.     DSP_wbox(FSEL_X1,FSEL_Y1,FSEL_X2,FSEL_Y2,LINE_COL,FILD_COL,M_PSET);
  1617.     gputs(FSEL_MSG_X,FSEL_MSG_Y,CHR_COL,FILD_COL,"FILE SELECTER");
  1618.  
  1619.     ep = EVT_sw(ep,0,FSEL_EXIT_X,FSEL_EXIT_Y,CHR_COL,WIND_COL,"×");
  1620.     ep = EVT_sw(ep,1,FSEL_BACK_X,FSEL_BACK_Y,CHR_COL,WIND_COL,"△");
  1621.     ep = EVT_sw(ep,2,FSEL_NEXT_X,FSEL_NEXT_Y,CHR_COL,WIND_COL,"▽");
  1622.  
  1623.     for ( i = n = 0 ; i < 17 ; i++ ) {
  1624.     if ( drv_tbl[i] != IS_NON ) {
  1625.         ICON_disp(FSEL_DPOS_X1(n),FSEL_DPOS_Y1(n),i);
  1626.         ep = EVT_set(ep,i+100,
  1627.             FSEL_DPOS_X1(n),FSEL_DPOS_Y1(n),
  1628.                 FSEL_DPOS_X2(n),FSEL_DPOS_Y2(n),EVT_proc);
  1629.         drv_no[i] = n;
  1630.         n++;
  1631.     } else
  1632.         drv_no[i] = 17;
  1633.     }
  1634.  
  1635.     for ( i = 0 ; i < 15 ; i++ ) {
  1636.     ep = EVT_set(ep,i+200,
  1637.         FSEL_FPOS_X1(i),FSEL_FPOS_Y1(i),
  1638.             FSEL_FPOS_X2(i),FSEL_FPOS_Y2(i),EVT_proc);
  1639.     DSP_wbox(FSEL_FPOS_X1(i),FSEL_FPOS_Y1(i),
  1640.              FSEL_FPOS_X2(i),FSEL_FPOS_Y2(i),LINE_COL,WIND_COL,M_PSET);
  1641.     }
  1642.  
  1643.     DSP_wbox(FSEL_DIR_X-4,FSEL_DIR_Y-2,
  1644.          FSEL_DIR_X+(44*8)+2,FSEL_DIR_Y+17,LINE_COL,WIND_COL,M_PSET);
  1645.  
  1646.     MOS_rdpos(&sw,&bx,&by);
  1647.     MOS_setpos((FSEL_X1+FSEL_X2)/2,(FSEL_Y1+FSEL_Y2)/2);
  1648.     MOS_disp(ON);
  1649.  
  1650.     drv_now = getdrv();
  1651.     drv_old = ERR;
  1652.     dir_flg = TRUE;
  1653.     dirp = NULL;
  1654.     pos_old = ERR;
  1655.     pos_now = 0;
  1656.  
  1657.     for ( cd = FALSE ; cd == FALSE ; ) {
  1658.  
  1659.     if ( drv_old != drv_now ) {
  1660.         MOS_disp(OFF);
  1661.         if ( drv_old != ERR )
  1662.         DSP_box(FSEL_DPOS_X1(drv_no[drv_old]),
  1663.             FSEL_DPOS_Y1(drv_no[drv_old]),
  1664.             FSEL_DPOS_X2(drv_no[drv_old]),
  1665.             FSEL_DPOS_Y2(drv_no[drv_old]),
  1666.             11,M_XOR);
  1667.  
  1668.         DSP_box(FSEL_DPOS_X1(drv_no[drv_now]),
  1669.             FSEL_DPOS_Y1(drv_no[drv_now]),
  1670.             FSEL_DPOS_X2(drv_no[drv_now]),
  1671.             FSEL_DPOS_Y2(drv_no[drv_now]),
  1672.             11,M_XOR);
  1673.         MOS_disp(ON);
  1674.  
  1675.         DSP_mos(2);
  1676.         chdrv(drv_now);
  1677.         DSP_mos(0);
  1678.  
  1679.         drv_old = drv_now;
  1680.         dir_flg = TRUE;
  1681.     }
  1682.  
  1683.     if ( dir_flg != FALSE ) {
  1684.         DSP_mos(2);
  1685.         getdir(tmp);
  1686.  
  1687.         MOS_disp(OFF);
  1688.         gprintf(FSEL_DIR_X,FSEL_DIR_Y,CHR_COL,WIND_COL,"%-44.44s",tmp);
  1689.         MOS_disp(ON);
  1690.  
  1691.         if ( tmp[1] != '\0' )
  1692.         strcat(tmp,"\\");
  1693.         strcat(tmp,"*.*");
  1694.         if ( dirp !=  NULL )
  1695.         closedir(dirp);
  1696.         dirp = opendir(tmp);
  1697.         dir_max = countdir(dirp);
  1698.         pos_now = 0;
  1699.         pos_old = ERR;
  1700.         dir_flg = FALSE;
  1701.         DSP_mos(0);
  1702.     }
  1703.  
  1704.     if ( pos_old != pos_now ) {
  1705.         seekdir(dirp,pos_now);
  1706.         MOS_disp(OFF);
  1707.         for ( i = 0 ; i < 15 ; i++ ) {
  1708.         dp = readdir(dirp);
  1709.         gputs(FSEL_FPOS_X1(i)+4,FSEL_FPOS_Y1(i)+2,
  1710.             (IS_DIR(dp) ? KEY_COL:CHR_COL),WIND_COL,
  1711.             (dp != NULL ? 
  1712.                   formname(dp->d_name):"              "));
  1713.         file_ptr[i] = dp;
  1714.         }
  1715.         MOS_disp(ON);
  1716.         pos_old = pos_now;
  1717.     }
  1718.  
  1719.     i = EVT_wait(ep);
  1720.  
  1721.     if ( i == 0 ) {
  1722.         cd = ERR;
  1723.  
  1724.     } else if ( i == 1 ) {
  1725.         if ( pos_now > 0 )
  1726.         pos_now -= 15;
  1727.  
  1728.     } else if ( i == 2 ) {
  1729.         if ( (pos_now + 15) < dir_max )
  1730.              pos_now += 15;
  1731.  
  1732.     } else if ( i >= 200 ) {
  1733.         if ( (dp = file_ptr[i-200]) != NULL ) {
  1734.         if ( IS_DIR(dp) ) {
  1735.             chdir(dp->d_name);
  1736.             dir_flg = TRUE;
  1737.         } else {
  1738.             strcpy(tmp,dp->d_name);
  1739.             cd = TRUE;
  1740.         }
  1741.         }
  1742.  
  1743.     } else if ( i >= 100 ) {
  1744.         drv_now = i - 100;
  1745.         dir_flg = TRUE;
  1746.     }
  1747.     }
  1748.  
  1749.     if ( dirp != NULL )
  1750.     closedir(dirp);
  1751.  
  1752.     EVT_free(ep);
  1753.     MOS_disp(OFF);
  1754.     DSP_pop_vram(sp);
  1755.     DSP_clbox(FSEL_X1,FSEL_Y1,FSEL_X2,FSEL_Y2);
  1756.     MOS_setpos(bx,by);
  1757.     MOS_disp(ON);
  1758.  
  1759.     return (cd == ERR ? NULL:tmp);
  1760. }
  1761.